const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../services/user.js');

//获取应用实例
const app = getApp()
Page({
  data: {
    banner: [{
      "createTime": "2019-06-29 22:43:24",
      "id":3,
"linkUrl":"https://knowif.oss-cn-beijing.aliyuncs.com/tutorPicture/%E5%B0%8F%E7%A8%8B%E5%BA%8Fbanner/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20190629223810.png",
"picUrl":"https://knowif.oss-cn-beijing.aliyuncs.com/tutorPicture/%E5%B0%8F%E7%A8%8B%E5%BA%8Fbanner/banner.png"
    }],
    project: [{
        itemName: '房型介绍',
        itemPic: '../../images/index/home_icon.png',
        linkUrl: '../../myPages/hostelTypes/hostelTypes'
      },
      {
        itemName: '关于我们',
        itemPic: '../../images/index/about_icon.png',
        linkUrl: '../../myPages/hostelAbout/hostelAbout'
      },
      {
        itemName: '我要订房',
        itemPic: '../../images/index/book_icon.png',
        linkUrl: '../../myPages/hostelBook/hostelBook'
      },
      {
        itemName: '地图导航',
        itemPic: '../../images/index/map_icon.png',
        linkUrl: '../../myPages/gzh/gzh?link=https://mp.weixin.qq.com/s/q_lJbxhKY4m6hVsID8GC_Q'
      },
      {
        itemName: '韩国代购',
        itemPic: '../../images/index/job_icon.png',
        linkUrl: '../../myPages/shop/shopList/shopList'
      },
      {
        itemName: '进实习群',
        itemPic: '../../images/index/group_icon.png',
        linkUrl: '../../pages/shixi/shixi'
      }
    ],
    recommendTeacher: [],
    imgalist: ['https://knowif.oss-cn-beijing.aliyuncs.com/tutorPicture/%E5%B0%8F%E7%A8%8B%E5%BA%8Fbanner/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20190629223810.png']
  },
  onShareAppMessage: function() {
    return {
      title: 'zhishiya',
      desc: '知识鸭',
      path: '/pages/index/index'
    }
  },
  getIndexData: function() {
    let that = this;
    util.request(api.IndexUrl).then(function(res) {
      if (res.code === 200) {
        //设置介绍文字
        that.setData({
          banner: res.result.banners,
          // project: res.result.items,
        });
      }
    });
  },
  goToProject: function(e) {
    // let getName = e.currentTarget.dataset.name;
    // if (getName == '进实习群') {
    //   wx.showToast({
    //     title: '信息更新中，敬请期待',
    //     icon: 'none'
    //   })
    // } else {
      
    // }
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },

  //图片预览
  previewImage: function(e) {
    console.log(e.currentTarget.dataset.linkurl)
    if (e.currentTarget.dataset.linkurl != '') {
      var url = [e.currentTarget.dataset.linkurl];
      wx.previewImage({
        current: url, // 当前显示图片的http链接   
        urls: url // 需要预览的图片http链接列表   
      })
      wx.getImageInfo({ // 获取图片信息
        src: url[0],
        success: function(res) {
          // console.log(res.width)
          // console.log(res.height)
        }
      })
    }
  },
  onLoad: function(options) {

  },
  onReady: function() {

  },
  onShow: function() {
    // 页面显示  城市定位信息
  },
  onHide: function() {
    // 页面隐藏
  },
  onUnload: function() {
    // 页面关闭
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    let that = this;
    return {
      title: '知识鸭', // 转发后 所显示的title
      path: '/pages/index/index', // 相对的路径
      imageUrl: "/images/common/share_app.png",
      success: (res) => { // 成功后要做的事情
        wx.getShareInfo({
          shareTicket: res.shareTickets[0],
          success: (res) => {},
          fail: function(res) {
            console.log(res)
          },
          complete: function(res) {
            console.log(res)
          }
        })
      },
      fail: function(res) {
        // 分享失败
        console.log(res)
      }
    }
  }
})